<template>
  <div class="wrapper">
   <div style="margin: 100px auto; background-color: #fff; width: 350px;height: 400px; padding: 20px;border-radius: 10px">
     <div style="margin: 20px 0; text-align: center; font-size: 24px"><b>注 册</b></div>
     <el-form :model="user" :rules="rules" ref="userForm" >
       <el-form-item prop="username">
       <el-input size="medium" placeholder="请输入用户名" style="margin: 10px 0" prefix-icon="el-icon-user" v-model="user.username" clearable autocomplete="off"></el-input>
       </el-form-item>
       <el-form-item prop="password">
       <el-input size="medium" placeholder="请输入密码" style="margin: 10px 0" prefix-icon="el-icon-lock" v-model="user.password" show-password clearable autocomplete="off"></el-input>
       </el-form-item>
     </el-form>
       <div style="margin: 10px 0; text-align: right">
         <el-button type="primary" size="small" autocomplete="off" @click="$router.push('/')">取消</el-button>
         <el-button type="warning" size="small" autocomplete="off" @click="Register">注册</el-button>
       </div>
     </div>
   </div>
</template>

<script>
import request from "@/utils/request";
import StaffInfo from "@/views/StaffInfo.vue";
import router from "@/router";

export default {
  name: "Login",
  data() {
    return {
      user: {},
      userForm:{
        username:'',
        password:'',
      },
      rules: {
        username: [
          {
            required: true,
            message: '请输入用户名',
            trigger: 'blur'
          },
        ],password: [
          {
            required: true,
            message: '请输入密码',
            trigger: 'blur'
          }
          ],
      },
    }
  },
  methods:{
    router() {
      return router
    },
    Register() {
      this.$refs['userForm'].validate((valid) => {
        if (valid) {
          request.post("/register", this.user).then(res => {
            if (res.code==="200") {
              localStorage.setItem("user",JSON.stringify(res.data))
              this.$router.push("/")
            } else {
              this.$message.error("用户名已存在")
            }
          })
          //alert('submit!');
        } else {
          //console.log('error submit!!');
          return false;
        }
      });
    },
  }
}
</script>

<style>
.wrapper{
  height: 100vh;
  background-image: linear-gradient(to bottom right,#FC466B,#3f5efb);
  overflow: hidden;
}

</style>
